//
//  ZZCMyLabourController.m
//  ZZC-Finance
//
//  Created by a on 2017/8/19.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCMyLabourController.h"

@interface ZZCMyLabourController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate,UIWebViewDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *myLabourWebV;

@end

@implementation ZZCMyLabourController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    float chacha = [[NSUserDefaults standardUserDefaults] floatForKey:@"appchacha"];
    chacha += 0.03;
    [[NSUserDefaults standardUserDefaults] setFloat:chacha forKey:@"appchacha"];

    self.navigationController.delegate = self;
    self.myLabourWebV.delegate = self;
    // Do any additional setup after loading the view from its nib.
    NSString *token = ZZCNSUserDefaults(@"token");
    NSURL *h5_assetStatus = [NSURL URLWithString:[NSString stringWithFormat:@"%@?token=%@",ZZCURL_API_H5_CHOOSE_COMM,token]];
    NSURLRequest *request = [NSURLRequest requestWithURL:h5_assetStatus];
    NSLog(@"%@",h5_assetStatus);
    //让内容自动适应屏幕大小
    self.myLabourWebV.scrollView.bounces = NO;
    self.myLabourWebV.scalesPageToFit = YES;
    [self.myLabourWebV loadRequest:request];
    [self.view addSubview:self.myLabourWebV];
    
    
    
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"%@",request);
    if ([request.URL.absoluteString containsString:@"http://www.stlh.com/action===back"]) {
        NSLog(@"已拦截");
        [self.navigationController popToRootViewControllerAnimated:YES];
        
        
        return NO;
        
    }
    if ([request.URL.absoluteString containsString:@"http://www.stlh.com/action===photo"]) {
        [self getImage];
        //        NSString *methodName = @"photo";
        
        NSString *url = @"http://bpic.588ku.com/back_pic/00/00/69/40/e813e05e7e2a4039313a82cd1ef3de02.jpg!ww800";
        NSString * str = [NSString stringWithFormat:@"photo('%@')",url];
        
        [self.myLabourWebV stringByEvaluatingJavaScriptFromString:str];
        
        return NO;
    }
    return YES;
    
}

- (void)getImage {
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { //调用相册
        //实例化控制器
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.delegate = self;
        // 是否有图片选取框
        picker.allowsEditing = YES;
        [self presentViewController:picker animated:YES completion:nil];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
